import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["executorId"];

/**
 * model 任务执行器
 * @date: 2018-9-3


 */
import request from 'utils/request';
import { CPAAS_SDR } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel, parseParameters } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
var organizationRoleLevel = isTenantRoleLevel();
/**
 * 请求API前缀
 * @type {string}
 */

var prefix = "".concat(CPAAS_SDR, "/v1");
/**
 * 查询执行器列表数据
 * @async
 * @function fetchGroupsList
 * @param {object} params - 查询条件
 */

export function fetchGroupsList(_x) {
  return _fetchGroupsList.apply(this, arguments);
}
/**
 * 创建执行器
 * @async
 * @function createGroups
 * @param {object} params - 创建参数
 */

function _fetchGroupsList() {
  _fetchGroupsList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executors") : "".concat(prefix, "/executors"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchGroupsList.apply(this, arguments);
}

export function createGroups(_x2) {
  return _createGroups.apply(this, arguments);
}
/**
 * 更新执行器
 * @async
 * @function updateGroups
 * @param {object} params - 参数
 */

function _createGroups() {
  _createGroups = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executors") : "".concat(prefix, "/executors"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _createGroups.apply(this, arguments);
}

export function updateGroups(_x3) {
  return _updateGroups.apply(this, arguments);
}
/**
 * 删除执行器
 * @async
 * @function deleteGroups
 * @param {object} params - 参数
 */

function _updateGroups() {
  _updateGroups = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executors") : "".concat(prefix, "/executors"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _updateGroups.apply(this, arguments);
}

export function deleteGroups(_x4) {
  return _deleteGroups.apply(this, arguments);
}
/**
 * 查询执行器配置列表数据
 * @async
 * @function fetchGroupsList
 * @param {object} params - 查询条件
 */

function _deleteGroups() {
  _deleteGroups = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executors") : "".concat(prefix, "/executors"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _deleteGroups.apply(this, arguments);
}

export function fetchExecutorList(_x5) {
  return _fetchExecutorList.apply(this, arguments);
}
/**
 * 效验执行器配置列表数据
 * @async
 * @function fetchGroupsList
 * @param {object} params - 查询条件
 */

function _fetchExecutorList() {
  _fetchExecutorList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            return _context5.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executor-configs/").concat(params.executorId, "/config") : "".concat(prefix, "/executor-configs/").concat(params.executorId, "/config"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _fetchExecutorList.apply(this, arguments);
}

export function checkExecutor(_x6) {
  return _checkExecutor.apply(this, arguments);
}
/**
 * 删除执行器配置项
 * @async
 * @function deleteExecutor
 * @param {object} params - 查询条件
 */

function _checkExecutor() {
  _checkExecutor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executor-configs/").concat(params.executorId, "/check") : "".concat(prefix, "/executor-configs/").concat(params.executorId, "/check"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _checkExecutor.apply(this, arguments);
}

export function deleteExecutor(_x7) {
  return _deleteExecutor.apply(this, arguments);
}
/**
 * 更新执行器配置项
 * @async
 * @function updateExecutor
 * @param {object} params - 查询条件
 */

function _deleteExecutor() {
  _deleteExecutor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executor-configs") : "".concat(prefix, "/executor-configs"), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _deleteExecutor.apply(this, arguments);
}

export function updateExecutor(_x8) {
  return _updateExecutor.apply(this, arguments);
}
/**
 * 执行器列表配置
 * @async
 * @function executorConfig
 * @param {object} params - 查询条件
 */

function _updateExecutor() {
  _updateExecutor = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            return _context8.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executor-configs") : "".concat(prefix, "/executor-configs"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _updateExecutor.apply(this, arguments);
}

export function executorConfig(_x9) {
  return _executorConfig.apply(this, arguments);
}
/**
 * 执行器列表配置
 * @async
 * @function executorConfig
 * @param {object} params - 查询条件
 */

function _executorConfig() {
  _executorConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(params) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executor-configs/").concat(params.executorId, "/config") : "".concat(prefix, "/executor-configs/").concat(params.executorId, "/config"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _executorConfig.apply(this, arguments);
}

export function executorConfigByJob(_x10) {
  return _executorConfigByJob.apply(this, arguments);
}

function _executorConfigByJob() {
  _executorConfigByJob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    var executorId, others;
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            executorId = params.executorId, others = _objectWithoutProperties(params, _excluded);
            return _context10.abrupt("return", request(organizationRoleLevel ? "".concat(prefix, "/").concat(organizationId, "/executor-configs/").concat(executorId, "/by-job") : "".concat(prefix, "/executor-configs/").concat(executorId, "/by-job"), {
              method: 'GET',
              query: others
            }));

          case 2:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _executorConfigByJob.apply(this, arguments);
}